package com.seplayer.service.test;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class BindService extends Service {

	private int count;
	private boolean quit;
	private MyBinder binder=new MyBinder();
	public class MyBinder extends Binder{
		public int getCount(){
			return count;
		}
	}
	public IBinder onBind(Intent intent) {
		System.out.println("Service is binded!");
		return binder;
	}
	public void onCreate() {
		super.onCreate();
		System.out.println("Service is created!");
		new Thread(){
			public void  run(){
				while(!quit){
					try {
						sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					count++;
				}
			}
		}.start();
	}
	public boolean onUnbind(Intent intent) {
		System.out.println("Service is unbinded!");
		return true;
	}
	@Override
	public void onDestroy() {
		super.onDestroy();
		this.quit=true;
		System.out.println("Service is destroyed!");
	}
}
